package com.wsoft.im.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.im.query.member.config.MemberListQuery;
import com.wsoft.im.query.member.config.WhiteConfigQuery;
import com.wsoft.im.service.IImMemberConfigService;
import com.wsoft.im.vo.MemberConfigVO;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *  前端控制器
 * @author Z001
 * @since 2025年01月14日 09:21:32
 */
@RestController
@Tag(name = "白/黑名单配置-管理端")
@RequestMapping("/im/config")
public class ImMemberConfigController {


    @Resource
    private IImMemberConfigService memberConfigService;

    @Operation(summary = "管理员配置白名单列表", description = "管理员配置白名单列表")
    @PostMapping("/addWhiteList")
    public ResponseResult addWhiteList(@RequestBody @Valid WhiteConfigQuery query) {
        boolean b = memberConfigService.addWhiteList(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


    @Operation(summary = "管理员移除白名单列表", description = "管理员配置白名单列表")
    @PostMapping("/removeWhiteList")
    public ResponseResult removeWhiteList(@RequestBody @Valid WhiteConfigQuery query) {
        boolean b = memberConfigService.removeWhiteList(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


    @Operation(summary = "管理员获取白名单列表", description = "管理员获取白名单列表")
    @PostMapping("/getWhiteList")
    public ResponseResult getWhiteList(@RequestBody @Valid MemberListQuery query) {
        PageInfo<MemberConfigVO> page = memberConfigService.getWhiteList(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }





}
